#include "Transform.h"

#include "glm\gtc\matrix_transform.hpp"

Transform::Transform()
{
	modelMatrix = glm::mat4(1.0f);
	right = glm::vec3(1, 0, 0);
	up = glm::vec3(0, 1, 0);
	forward = glm::vec3(0, 0, 1);


}

Transform::~Transform()
{

}

void Transform::Translate(glm::vec3 vec)
{
	modelMatrix = glm::translate(modelMatrix, vec);
}

//roll = z, pitch = x, yaw = y
void Transform::Rotate(float roll, float pitch, float yaw)
{
	glm::quat rollQ = glm::quat(cos(roll/2.0f), 0, 0, sin(roll/2.0f));
	glm::quat pitchQ = glm::quat(cos(pitch/2.0f), sin(pitch/2.0f), 0, 0);
	glm::quat yawQ = glm::quat(cos(yaw/2.0f), 0, sin(yaw/2.0f), 0);

	glm::quat invRollQ = glm::inverse(rollQ);
	glm::quat invPitchQ = glm::inverse(pitchQ);
	glm::quat invYawQ = glm::inverse(yawQ);


}

//force set the matrix, we update the right up and forward vectors from the matrix
void Transform::SetModelMatrix(glm::mat4 matrix)
{
	modelMatrix = matrix;
	glm::vec4 rightV4 = modelMatrix * glm::vec4(1.0f, 0.0f, 0.0f, 0.0f);// * glm::vec4(right.x, right.y, right.z, 0.0f);
	glm::vec4 upV4 = modelMatrix * glm::vec4(0.0f, 1.0f, 0.0f, 0.0f);// * glm::vec4(up.x, up.y, up.z, 0.0f);
	glm::vec4 forwardV4 = modelMatrix * glm::vec4(0.0f, 0.0f, 1.0f, 0.0f);// * glm::vec4(forward.x, forward.y, forward.z, 0.0f);

	right = glm::vec3(rightV4.x, rightV4.y, rightV4.z);
	up = glm::vec3(upV4.x, upV4.y, upV4.z);
	forward = glm::vec3(forwardV4.x, forwardV4.y, forwardV4.z);
}

glm::mat4 Transform::GetModelMatrix()
{
	return modelMatrix;
}